<?php

declare(strict_types=1);
/**
 * This file is part of MineAdmin.
 *
 * @link     https://www.mineadmin.com
 * @document https://doc.mineadmin.com
 * @contact  root@imoi.cn
 * @license  https://github.com/mineadmin/MineAdmin/blob/master/LICENSE
 */

namespace App\Schema;

use App\Model\Classroom;
use App\Model\Permission\User;
use Hyperf\Swagger\Annotation\Property;
use Hyperf\Swagger\Annotation\Schema;

#[Schema]
final class ClassroomSchema implements \JsonSerializable
{
    public function __construct(
        Classroom $model,
        #[Property(property: 'name', title: '班级名称', type: 'string')]
        public ?string $name,
        #[Property(property: 'school_id', title: '所属学校', type: 'int')]
        public ?int $school_id,
        #[Property(property: 'teacher_id', title: '责任教师', type: 'int')]
        public ?int $teacher_id,
        #[Property(property: 'department_id', title: '所属院系', type: 'int')]
        public ?int $department_id,
        #[Property(property: 'member_count', title: '班级人数', type: 'int')]
        public ?int $member_count,
        #[Property(property: 'creator_id', title: '创建者', type: 'int')]
        public ?int $creator_id,
        #[Property(property: 'creator', title: '创建者', type: 'array')]
        public ?User $creator,
        #[Property(property: 'teachers', title: '分配教师', type: 'array')]
        public ?array $teachers
    ) {

        foreach (
            get_class_vars(__CLASS__)
            as $var
        ) {
            $this->{$var} = $model->${$var};
        }
    }

    public function jsonSerialize(): mixed
    {
        $json = [];
        foreach (
            get_class_vars(__CLASS__)
            as $var
        ) {
            $json[$var] = $this->{$var};
        }
        return $json;
    }
}
